<template>
	<div class="myOrder-box">
		<!-- 头部 -->
		<div class="header"><TopBar topTabTitle="我的订单"></TopBar></div>

		<!-- 内容 -->
		<div class="content-box">
			<ul class="order">
				<li v-for="order in orderList" :key="order.orderNumber">
					<div class="order-title">
						<p>订单编号：{{ order.orderNumber }}</p>
						<p>完成</p>
					</div>
					<div class="goods" v-for="goods in order.goodsList" :key="goods.id">
						<p>{{ goods.name }}</p>
						<p class="goods-price">￥{{ goods.price }}</p>
					</div>
					<div class="operation"><button @click="orderDel(order.orderNumber)">删除</button></div>
				</li>
			</ul>
		</div>
	</div>
</template>

<script>
import TopBar from '@/components/topTab.vue';
export default {
	name: 'myOrder',
	data() {
		return {
			orderList: []
		};
	},
	methods: {
		orderDel(num) {
			this.orderList.forEach((item, index) => {
				if (item.orderNumber == num) {
					this.orderList.splice(index, 1);
				}
			});
			localStorage.setItem('orderList', JSON.stringify(this.orderList));
		}
	},
	created() {
		this.orderList = localStorage.getItem('orderList') ? JSON.parse(localStorage.getItem('orderList')) : [];
	},
	mounted() {
		document.querySelector('.content-box').style.height = document.documentElement.clientHeight + 'px';
	},
	components: {
		TopBar
	}
};
</script>

<style scoped="scoped">
@import url('../css/publice.css');
.header {
	width: 100%;
	padding: 0 0.05rem;
	border-bottom: #ddd solid 0.01rem;
	position: fixed;
	top: 0;
	z-index: 3;
}
.content-box {
	width: 100%;
	position: fixed;
	top: 0.92rem;
	background-color: #f5f5f5;
	overflow: auto;
}
.order {
	width: 100%;
	display: flex;
	flex-direction: column;
	justify-content: flex-start;
	align-items: center;
}
.order li {
	width: 90%;
	margin-top: 0.3rem;
	background-color: white;
	border-radius: 0.1rem;
	padding: 0.2rem;
}
.order-title {
	width: 100%;
	display: flex;
	justify-content: space-between;
	height: 0.6rem;
	font-size: 0.3rem;
	border-bottom: #ddd solid 0.01rem;
	margin-bottom: 0.2rem;
}
.goods {
	width: 100%;
	display: flex;
	justify-content: space-between;
}
.goods-price {
	color: #f42424;
}
.operation {
	width: 100%;
	margin-top: 0.3rem;
	display: flex;
	justify-content: flex-end;
}

.operation button {
	width: 1.5rem;
	height: 0.5rem;
	border: none;
	border-radius: 0.1rem;
	background-color: #f5f5f5;
}
</style>
